<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //Object.defineProperty主要是为已经存在的对象添加属性,或者修改现有属性。如果指定的属性名在对象中不存在,则执行添加操作:如果在对象中存在同名属性,则执行修改操作
        const obj ={
            name:"xiaogao",
            age:19
        }
        Object.defineProperty(obj,"age",{
            get(){
                console.log("获取值了")
                return 20
            },
            set(newValue){
                    console.log("更新了"+newValue)
            }
        })
        obj.age++
    </script>
</body>
</html>